import java.util.Arrays;
import java.util.List;

/**
 * @author lirns
 * @date 2021/11/25 11:35
 */
public class Demo {
    public static void main(String[] args) {
        Demo demo = new Demo();
        System.out.println("测试 testListToTreeAndOne");
        demo.testListToTreeAndOne();
        System.out.println("\n\n\n\n测试 testListToTreeAndOneWithIf");
        demo.testListToTreeAndOneWithIf();
        System.out.println("\n\n\n\n测试 testListToTree");
        demo.testListToTree();
        System.out.println("\n\n\n\n测试 testListToTreeWithIf");
        demo.testListToTreeWithIf();
    }


    public void testListToTreeAndOneWithIf() {
        // 非CommonTree类
        Tree1 t0 = new Tree1(null, "0", 0, 0);
        Tree1 t1 = new Tree1("0", "1", 0, 1);
        Tree1 t2 = new Tree1("0", "2", 0, 1);
        Tree1 t3 = new Tree1("1", "3", 1, 2);
        List<ICommonTree> iCommonTreeList = Arrays.<ICommonTree>asList(t0, t1, t2, t3);
        CommonTree tree1 = CommonTreeUtil.listToTreeAndOneWithIf(iCommonTreeList);
        System.out.println("--------------------------------");
        System.out.println("接口类生成一棵树");
        System.out.println(tree1);
        System.out.println("--------------------------------");
    }

    public void testListToTreeAndOne() {
        // CommonTree类
        CommonTree c0 = new CommonTree(null, "0", "0", 0, 0);
        CommonTree c1 = new CommonTree("0", "1", "1", 0, 1);
        CommonTree c2 = new CommonTree("0", "2", "2", 0, 1);
        CommonTree c3 = new CommonTree("1", "3", "3", 1, 2);
        CommonTree tree2 = CommonTreeUtil.listToTreeAndOne(Arrays.asList(c0, c1, c2, c3));
        System.out.println("--------------------------------");
        System.out.println("公共树类生成一棵数");
        System.out.println(tree2);
        System.out.println("--------------------------------");
    }

    public void testListToTree() {
        CommonTree c1 = new CommonTree(null, "1", "1", 0, 0);
        CommonTree c2 = new CommonTree(null, "2", "2", 0, 0);
        CommonTree c3 = new CommonTree("1", "3", "3", 1, 1);
        // 生成多节点树
        List<CommonTree> tree1 = CommonTreeUtil.listToTree(Arrays.asList(c1, c2));
        System.out.println("--------------------------------");
        System.out.println("生成多节点树");
        System.out.println(tree1);
        System.out.println("--------------------------------");
        // 向指定节点挂载树
        CommonTreeUtil.listToTree(c1, Arrays.asList(c3));
        System.out.println("--------------------------------");
        System.out.println("公共树类 向指定节点挂载树");
        System.out.println(c1);
        System.out.println("--------------------------------");
    }

    public void testListToTreeWithIf() {
        Tree1 t0 = new Tree1(null, "0", 0, 0);
        Tree1 t1 = new Tree1("0", "1", 0, 1);
        Tree1 t2 = new Tree1("0", "2", 0, 1);
        Tree1 t3 = new Tree1("1", "3", 1, 2);
        Tree2 tt1 = new Tree2("0", "1", 0, 1);
        Tree2 tt2 = new Tree2("1", "2", 1, 2);
        Tree2 tt3 = new Tree2("1", "3", 1, 2);

        List<CommonTree> tree1 = CommonTreeUtil.listToTreeWithIf(Arrays.<ICommonTree>asList(t0, t1, t2, t3));
        System.out.println("--------------------------------");
        System.out.println("接口类生成树");
        System.out.println(tree1);
        System.out.println("--------------------------------");

        CommonTree tree2 = CommonTreeUtil.listToTreeWithIf(t1, Arrays.<ICommonTree>asList(tt3));
        System.out.println("--------------------------------");
        System.out.println("接口类挂载树 不同实体类组装成树");
        System.out.println(tree2);
        System.out.println("--------------------------------");

        CommonTree tree3 = CommonTreeUtil.listToTreeWithIf(tt1, Arrays.<ICommonTree>asList(tt2));
        System.out.println("--------------------------------");
        System.out.println("向接口节点挂载接口树 返回公共树");
        System.out.println(tree3);
        System.out.println("--------------------------------");

    }

}
